var easeFs = {
    timewarp :function(p){
        if(p<=0.5)return -Math.sqrt(0.25 - p*p) + 0.5;
        return Math.sqrt(-0.75 + 2*p- p*p) + 0.5;
    },
    easeout:function(p){
        return -(1-p)*(1-p)*(1-p) +1;
    },
    qc:function(p){
        return Math.sqrt(-(p-1)*(p-1)+1);
    }
} 

function Anime(startTime,during,startValue,endValue,ease){
    this.start = startTime;
    this.during = during;
    this.endValue = endValue;
    this.startValue = startValue;
    this.ease = easeFs[ease]||easeFs.timewarp
}

Anime.prototype = {

    get percent(){
        var now = Date.now();
        if(now<this.start)return 0;
        if(now>this.start + this.during)return 1;
        return (now - this.start)/this.during;
    },

    get value(){
        var delta = this.endValue - this.startValue;
        return this.startValue + delta* this.ease(this.percent);
    }

}

export default Anime;

//用于检查函数曲线
// for(var i=0;i<=500;i++){
//     var k = $('<div></div>').css({
//         'position':'absolute',
//         'left':i*100/500 + 'px',
//         'top':Math.floor(100-easeFs.qc(i/500)*100) + 'px',
//         'width':1,
//         'height':1,
//         'background':'red'
//     }).appendTo('body');
// }